package com.sztest.jayjun.ui;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import com.sztest.jayjun.MainActivity;
import com.sztest.jayjun.MyApplication;
import com.sztest.jayjun.R;
import com.sztest.jayjun.utils.LogUtils;
import com.sztest.jayjun.utils.SystemPropertiesUtils;

import androidx.appcompat.app.AppCompatActivity;

/**
 * Created by elp on 2018/6/12.
 */

public class SplashActivity extends AppCompatActivity {
    private static int DELAYTIME = 2000;//延时时间
    private Handler handler = new Handler();
    Context mContext;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        setSystemUIVisible(false);
        setContentView(R.layout.activity_splash);
        mContext=this;
    }

    /**
     * 跳转到下一步
     */
    private Runnable jumpnext = new Runnable() {
        @Override
        public void run() {
//            Intent intent=new Intent(mContext,SettingsActivity.class);
//            Intent intent=new Intent(mContext,DebugActivity.class);
            Intent intent=new Intent(mContext, MainActivity.class);
            startActivity(intent);
            finish();
        }
    };


    @Override
    protected void onResume() {
        super.onResume();
        handler.postDelayed(jumpnext, DELAYTIME);
        LogUtils.e("com.sgj.bootani.exit    start");
//        MyApplication.getInstance().execRootCmd("setprop com.sgj.bootani.exit 1");
//        System.getProperties().setProperty("com.sgj.bootani.exit","1");
//        SystemProperties.
//        SystemProperties.getBoolean
//        String ret = System.setProperty("com.sgj.bootani.exit","1");
//        LogUtils.e("11:"+ret);
//         ret = System.setProperty("persist.my.bootanim.first","1");
//        LogUtils.e("22:"+ret);
//         ret = System.getProperty("service.bootanim.exit","6");
//        LogUtils.e("33:"+ret);
//
//        ret = System.setProperty("service.bootanim.exit","3");
//        LogUtils.e("44:"+ret);
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                SystemPropertiesUtils.setProperty("com.sgj.bootani.exit","1");
            }
        },1500);
        LogUtils.e("com.sgj.bootani.exit    end");
    }

    @Override
    protected void onPause() {
        super.onPause();
        handler.removeCallbacks(jumpnext);
    }

    private void setSystemUIVisible(boolean show) {
//        hideBottomUIMenu();
//        if (show) {
//            int uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
//            uiFlags |= 0x00001000;
//            getWindow().getDecorView().setSystemUiVisibility(uiFlags);
//        } else {
//            int uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
//                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
//                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
//                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
//                    | View.SYSTEM_UI_FLAG_FULLSCREEN;
//            uiFlags |= 0x00001000;
//            getWindow().getDecorView().setSystemUiVisibility(uiFlags);
//        }
    }

    /**
     * 隐藏虚拟按键，并且全屏
     */
    protected void hideBottomUIMenu() {
        //隐藏虚拟按键，并且全屏
        if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
            View v = this.getWindow().getDecorView();
            v.setSystemUiVisibility(View.GONE);
        } else if (Build.VERSION.SDK_INT >= 19) {
            //for new api versions.
            View decorView = getWindow().getDecorView();
            int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
            decorView.setSystemUiVisibility(uiOptions);
        }
    }

}
